﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace EWDTAssignment
{
    /// <summary>
    /// Summary description for verification
    /// </summary>
    public class verification : IHttpHandler, System.Web.SessionState.IRequiresSessionState 
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "image/JPEG";
            using(System.Drawing.Bitmap bitmap=new System.Drawing.Bitmap(50,20))
            {
                using(System.Drawing.Graphics g=System.Drawing.Graphics.FromImage(bitmap))
                {
                    Random random = new Random();
                    int verifyNum = random.Next(1000,9999);
                    string verifyCode = verifyNum.ToString();
                    HttpContext.Current.Session["verifyCode"] = verifyCode;
                    g.DrawString(verifyCode, new System.Drawing.Font("Algerian", 12), System.Drawing.Brushes.Green,new System.Drawing.PointF(0,0));
                    bitmap.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);

                }
            }
            
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}